<script>
	import API from "@/common/api.js";
	export default {
		globalData: {
			top: 0,
			bottom: 0
		},
		onLaunch: function(options) {
			//#ifdef APP-PLUS
			//plus.screen.lockOrientation("landscape-primary");
			plus.screen.lockOrientation("portrait-primary");
			//#endif
			var phone = uni.getSystemInfoSync()
			this.globalData.bottom = phone.safeAreaInsets.bottom;
			this.globalData.top = phone.safeAreaInsets.top

			//#ifdef MP-WEIXIN
			//var phone = uni.getSystemInfoSync()
			if (options.query.parentid != undefined) {
				var parentid = options.query.parentid;
			} else {
				var parentid = 0;
			}
			uni.setStorageSync("parentid", parentid)
			API.checkSession({
				parentid: 0
			});
			//#endif
			//#ifdef WEB
			var code = this.getUrlParam('code');
			var parentid = this.getUrlParam('parentid');

			if (parentid > 0) {
				uni.setStorageSync("parentid", parentid)
			} else {
				parentid = 0;
			}

			var ua = navigator.userAgent.toLowerCase();
			//判断是不是在公众号
			if (ua.match(/MicroMessenger/i) == "micromessenger") {
				var local = encodeURIComponent(window.location.href)
				API.post("user/getUser", {
					ext: 1
				}).then((res) => {
					if (res.code == 0) {
						if (code == null || code === '') {
							window.location.href =
								'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + res.data
								.gzhappid + '&redirect_uri=' +
								local +
								'&response_type=code&scope=snsapi_base&connect_redirect=1&state=#wechat_redirect';
						} else {
							this.getOpenId(code, parentid);
						}
					}
				})
			} else {
				//禁止在浏览器访问
				API.post("common/getParam").then((res) => {
					if (res.code == 1) {
						window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+res.data.appid
					}
				})
			}
			//#endif
		},
		onShow: function() {
			//console.log('App Show')
		},
		onHide: function() {
			//console.log('App Hide')
		},
		methods: {
			getOpenId(code, parentid = 0) {
				var $this = this
				API.post("user/openid", {
					code: code,
					parentid: parentid
				}).then((res) => {
					if (res.code == 1) {
						uni.setStorageSync("sessionid", res.data.sessionid)
					}
				})
			},
			getUrlParam(name) {
				let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
				let r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return unescape(r[2]);
				}
				return null;
			}
		}
	}
</script>

<style lang="scss">
	/* 全局引入iconfont */
	@import '@/static/icon/iconfont.css';

	/* #ifdef H5 */
	uni-page-head {
		display: none;
	}

	/* #endif */
	::v-deep .uni-tabbar .uni-tabbar__label {
		font-size: 14px !important;
	}

	.container {
		width: 100%;
		overflow: hidden;
		font-size: 24rpx;
		color: #222;
	}

	image {
		max-width: 100%;
		vertical-align: top;
	}

	.img {
		width: 100%;
	}

	button::after {
		border: none;
	}

	.fl {
		float: left;
	}

	.fr {
		float: right;
	}

	.tac {
		text-align: center;
	}

	.content {
		width: 100%;
		overflow: hidden;
		box-sizing: border-box;
	}

	.bgf {
		background: #fff;
	}

	.pad30 {
		padding: 0 30rpx;
	}

	.mgt20 {
		margin-top: 20rpx;
	}

	.mgt40 {
		margin-top: 40rpx;
	}

	.bordt20 {
		border-top: 20rpx #f7f7f7 solid;
	}

	.hdlist_state,
	.company_tel,
	.company_mapr text,
	.login_xeyi text,
	.login_dt text.getcode {
		color: $color;
	}

	.loginbtn {
		background: $color;
	}

	.ctitlebox {
		width: 100%;
		overflow: hidden;
		line-height: 48rpx;
	}

	.ctitle {
		font-size: 38rpx;
		font-weight: bold;
		float: left;
		position: relative;
		padding-left: 26rpx;
	}

	.ctitle::after {
		content: '';
		width: 8rpx;
		height: 32rpx;
		border-radius: 8rpx;
		background: $color;
		position: absolute;
		left: 0;
		top: 50%;
		transform: translateY(-50%);
	}

	.imore {
		float: right;
		color: #999;
		font-size: 26rpx;
	}

	.imore text {
		position: relative;
		float: right;
		margin: 10rpx 0 0 10rpx;
		width: 0;
		height: 0;
		border: 12rpx solid;
		border-color: transparent transparent transparent #999;
	}

	.imore text::after {
		content: '';
		position: absolute;
		top: -12rpx;
		left: -14rpx;
		border: 12rpx solid;
		border-color: transparent transparent transparent #fff;
	}

	.mapform {
		background: #fff;
		padding: 10rpx 30rpx;
	}

	.mapform_dl {
		padding: 10rpx 0;
		width: 100%;
		overflow: hidden;
		display: flex;
		border-bottom: 2rpx solid #eee;
		line-height: 100rpx;
		position: relative;
		font-size: 32rpx;
	}

	.mapform_dl:last-child {
		border-bottom: 0 solid #eee;
	}

	.mapform_dt {
		padding-right: 20rpx;
		font-weight: bold;
		font-size: 32rpx;
		line-height: 100rpx;
	}

	.mapform_dd {
		flex: 1;
		text-align: right;
		box-sizing: border-box;
		color: #555;
		position: relative;
	}

	.inp {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		border: 0 none;
		margin: 0;
		text-align: right;
		font-size: 32rpx;
	}

	.viptextarea {
		box-sizing: border-box;
		line-height: 46rpx;
		font-size: 32rpx;
		width: 100%;
		border: 0 none;
		text-align: left;
		height: 180rpx;
	}

	.mapform_ico {
		position: absolute;
		top: 38rpx;
		right: 0;
		width: 0;
		height: 0;
		border: 12rpx solid;
		border-color: transparent transparent transparent #b9b9b9;
	}

	.mapform_ico::after {
		content: '';
		position: absolute;
		top: -12rpx;
		left: -14rpx;
		border: 12rpx solid;
		border-color: transparent transparent transparent #fff;
	}

	.picker {
		display: block;
		height: 100rpx;
		line-height: 100rpx;
		padding-right: 40rpx;
	}

	.form_rbtn {
		display: inline-block;
		padding: 0 24rpx;
		border: 2rpx #4dd1a2 solid;
		color: #4dd1a2;
		height: 56rpx;
		line-height: 56rpx;
		border-radius: 56rpx;
		margin: 20rpx 0 0 20rpx;
		position: relative;
		box-sizing: border-box;
	}

	.formbottom {
		padding: 40rpx 30rpx;
	}

	.formbtn {
		width: 100% !important;
		height: 100rpx;
		line-height: 100rpx;
		background: $color;
		color: #fff;
		text-align: center;
		font-size: 36rpx;
		font-weight: bold;
		border-radius: 10rpx;
		padding: 0;
		margin-bottom: 30rpx;
	}

	.formbtn.del {
		background: #e3ecff;
		color: $color;
	}

	switch {
		transform: scale(.8);
	}

	.modal-mask {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background: #000;
		opacity: 0.5;
		overflow: hidden;
		z-index: 9000;
		color: #fff;
	}

	.modal-dialog {
		width: 80%;
		position: fixed;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		z-index: 9999;
		background: #fff;
		border-radius: 20rpx;
		font-size: 24rpx;
		color: #333;
	}

	.modal-title {
		text-align: center;
		font-size: 36rpx;
		font-weight: bold;
		overflow: hidden;
		width: 100%;
		box-sizing: border-box;
	}

	.modal-content {
		width: 100%;
		position: relative;
		padding: 30rpx;
		box-sizing: border-box;
	}

	.modal-box {
		width: 100%;
		box-sizing: border-box;
		line-height: 48rpx;
		max-height: 600rpx;
		overflow-y: auto;
		margin-top: 30rpx;
	}

	.modal-close {
		position: absolute;
		left: 50%;
		bottom: -100rpx;
		transform: translateX(-50%);
	}

	.modal-close view {
		transform: rotate(45deg);
		width: 80rpx;
		height: 80rpx;
		border-radius: 50rpx;
		background: #fff;
		display: block;
	}

	.modal-close view:after,
	.modal-close view:before {
		content: '';
		background: #222;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
	}

	.modal-close view:after {
		width: 40rpx;
		height: 4rpx;
	}

	.modal-close view:before {
		width: 4rpx;
		height: 40rpx;
	}
</style>